/*
 * Copyright (c) 2010, okazoh_tk. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  - Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *  - Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  - Neither the name of the copyright holder nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef ALKES_TREE_ILAYOUTER_H_INCLUDED_
#define ALKES_TREE_ILAYOUTER_H_INCLUDED_

#include "alkes/tree/internal.h"

namespace alkes {

/// \addtogroup scenegraph
//@{

enum HorizontalAlign
{
    AL_HALIGN_LEFT = 0,
    AL_HALIGN_CENTER,
    AL_HALIGN_RIGHT,
};

enum VerticalAlign
{
    AL_VALIGN_TOP = 0,
    AL_VALIGN_CENTER,
    AL_VALIGN_BOTTOM,
};

class AL_TREE_EXPORT ILayouter
{
public:
    ILayouter();
    virtual ~ILayouter() = 0;

    void setPadding(int16_t top, int16_t bottom, int16_t left, int16_t right);
    void setPaddingTop(int16_t top);
    void setPaddingBottom(int16_t bottom);
    void setPaddingLeft(int16_t left);
    void setPaddingRight(int16_t right);

    int16_t getPaddingTop() const;
    int16_t getPaddingBottom() const;
    int16_t getPaddingLeft() const;
    int16_t getPaddingRight() const;

    void setMargin(int16_t top, int16_t bottom, int16_t left, int16_t right);
    void setMarginTop(int16_t top);
    void setMarginBottom(int16_t bottom);
    void setMarginLeft(int16_t left);
    void setMarginRight(int16_t right);

    int16_t getMarginTop() const;
    int16_t getMarginBottom() const;
    int16_t getMarginLeft() const;
    int16_t getMarginRight() const;

    void setHorizontalAlign(HorizontalAlign halign);
    HorizontalAlign getHorizontalAlign() const;
    void setVerticalAlign(VerticalAlign valign);
    VerticalAlign getVerticalAlign() const;

    static void calcLayout(HorizontalAlign halign, const RectSize& outer_rect, const RectSize& inner_rect, Point2D::value_type& x);
    static void calcLayout(HorizontalAlign halign, const Rect& outer_rect, const RectSize& inner_rect, Point2D::value_type& x);
    static void calcLayout(VerticalAlign valign, const RectSize& outer_rect, const RectSize& inner_rect, Point2D::value_type& y);
    static void calcLayout(VerticalAlign valign, const Rect& outer_rect, const RectSize& inner_rect, Point2D::value_type& y);
    static void calcLayout(HorizontalAlign halign, VerticalAlign valign, const RectSize& outer_rect, const RectSize& inner_rect, Point2D& new_position);

    void beginLayout(const Rect& rect);
    void endLayout();
    void calcPosition(uint32_t index, const RectSize& size, Point2D& new_position);

protected:
    virtual void onBeginLayout(const Rect& rect) = 0;
    virtual void onEndLayout() = 0;
    virtual void onCalcPosition(uint32_t index, const RectSize& size, Point2D& new_position) = 0;

private:
    int16_t padding_top_, padding_bottom_, padding_left_, padding_right_;
    int16_t margin_top_, margin_bottom_, margin_left_, margin_right_;
    int8_t halign_, valign_;
};

//@}

}

#endif
